$(function (){
   $("#btn_summit").click(function (){
       var is = login_psw_verify() && login_id_verify();
       if(!is){
           alert("工号或密码不能为空！");
       }else{
           $.post($("#hidden_info").val()+"/Admin/login",$("#login_form").serialize(),function (data){
               if(data.flag){
                   location.href = "back.jsp";
               }else{
                   alert("登陆失败！工号或密码错误！");
               }
               return false;
           });
       }
       return false;
   });

   $("#btn_register").click(function (){
       location.href = "register.jsp";
   });

});

function login_id_verify(){
    var element = $("#InputID");
    var str = element.val();
    if(str){
        return true;
    }else{
        return false;
    }
}

function login_psw_verify(){
    var element = $("#InputPassword");
    var str = element.val();
    if(str){
        return true;
    }else{
        return false;
    }
}

function register_id_verify(){
    var element = $("#InputID");
    var str = element.val();
    var reg = /^\d+$/;
    var is = reg.exec(str);
    var span = $("#InputID_text");
    var path = $("#hidden_info").val();
    if(is){
        span.html("<img src="+path+"/images/right.png alt=\"right\" width=\"3%\" height=\"3%\">正确");
        span.attr("style","color: green;margin-left: 5px;");
        return true;
    }else{
        span.html("<img src="+path+"/images/error.png alt=\"error\" width=\"3%\" height=\"3%\">学号/工号不能为空或非数字");
        span.attr("style","color: red;margin-left: 5px;");
        return false;
    }
}

function register_psw_verify(){
    var element = $("#InputPassword");
    var str = element.val();
    var span = $("#InputPassword_text");
    var path = $("#hidden_info").val();
    if(str){
        span.html("<img src="+path+"/images/right.png alt=\"right\" width=\"3%\" height=\"3%\">正确");
        span.attr("style","color: green;margin-left: 5px;");
        return true;
    }else{
        span.html("<img src="+path+"/images/error.png alt=\"error\" width=\"3%\" height=\"3%\">密码不能为空");
        span.attr("style","color: red;margin-left: 5px;");
        return false;
    }
}

function register_name_verify(){
    var element = $("#InputName");
    var str = element.val();
    var span = $("#InputName_text");
    var path = $("#hidden_info").val();
    if(str){
        span.html("<img src="+path+"/images/right.png alt=\"right\" width=\"3%\" height=\"3%\">正确");
        span.attr("style","color: green;margin-left: 5px;");
        return true;
    }else{
        span.html("<img src="+path+"/images/error.png alt=\"error\" width=\"3%\" height=\"3%\">姓名不能为空");
        span.attr("style","color: red;margin-left: 5px;");
        return false;
    }
}

function register_phone_verify(){
    var element = $("#InputPhone");
    var str = element.val();
    var reg = /^[\d]{11}$/;
    var is = reg.exec(str);
    var span = $("#InputPhone_text");
    var path = $("#hidden_info").val();
    if(is){
        span.html("<img src="+path+"/images/right.png alt=\"right\" width=\"3%\" height=\"3%\">正确");
        span.attr("style","color: green;margin-left: 5px;");
        return true;
    }else{
        span.html("<img src="+path+"/images/error.png alt=\"error\" width=\"3%\" height=\"3%\">电话号码不能为空或有误");
        span.attr("style","color: red;margin-left: 5px;");
        return false;
    }
}